[#include "/common/macro/header.ftl" /]
[@header title="申请单管理" /]
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                        <form class="layui-form" action="" lay-filter="LAY-pla-system-apply-orders-list-filter-form">
                        <div style="margin-bottom: 10px;">
                            <div class="layui-form-item">
                                <div class="layui-input-inline">
                                    <script type="text/html" template>
                                        <select name="status">
                                            <option value="">申请单状态...</option>
                                            {{# for (var i in applyRecordType) { }}
                                            <option value="{{ i }}">{{ applyRecordType[i] }}</option>
                                            {{# } }}
                                        </select>
                                    </script>
                                </div>
                                <div class="LAY-list-btns">
                                    <button class="layui-btn layui-btn-primary" lay-submit
                                            lay-filter="LAY-pla-system-apply-orders-list-filter-form-query"><i
                                                class="layui-icon">&#xe615;</i>查询
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table id="LAY-system-apply-orders-table" lay-filter="LAY-system-apply-orders-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="LAY-system-apply-orders-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="audit">审核</a>
</script>

<script type="text/html" id="LAY-system-apply-orders-table-status-tpl">
    <input type="checkbox" lay-filter="LAY-system-apply-orders-table-enabled-btn" lay-skin="switch" lay-text="启用|禁用"
           {{#
           if(d.enabled){
           }}
           checked
           {{#
           }
           }} value="{{d.id}}">
</script>
<script src="${base}/static/layuiadmin/layui/layui.js"></script>
<script>
    var applyRecordType = {
        'APPLYING': '申请中',
        'APPLY_PASSED': '申请通过',
        'APPLY_FAIL': '申请失败'
    };
    layui.config({
        base: '${base}/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form'], function () {
        var $ = layui.$
            , admin = layui.admin
            , setter = layui.setter
            , response = setter.response
            , table = layui.table
            , view = layui.view
            , form = layui.form;

        table.render({
            elem: '#LAY-system-apply-orders-table'
            , url: '/admin/apply_records'
            , response: {
                statusCode: 20000 //成功的状态码，默认：0
            }
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度
            , page: true
            , cols: [[
                {field: 'id', title: '申请单编号', sort: true}
                , {field: 'applyName', title: '申请人', sort: true}
                , {
                    field: 'applyTime',
                    title: '申请时间',
                    sort: true
                }, {
                    field: 'returnTime',
                    title: '归还时间',
                    sort: true
                }, {
                    field: 'roomNo',
                    title: '申请的教室编号',
                    sort: true
                }, {
                    field: 'status',
                    title: '申请单状态',
                    sort: true
                }, {
                    title: '操作',
                    align: 'center',
                    fixed: 'right',
                    toolbar: '#LAY-system-apply-orders-table-bar',
                    unresize: true
                }
            ]]
        });

        //监听工具条
        table.on('tool(LAY-system-apply-orders-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'audit') {
                layer.confirm('是否进行审核？', function (index) {
                    admin.req({
                        url: '/admin/apply_records/audit/' + data.id
                        ,contentType:"application/json"
                        , type: 'post'
                        , success: function (res) {
                            var statusCode = response.statusCode;
                            if (res[response.statusName] === statusCode.ok) {
                                layer.msg('审核成功', {
                                    icon: 1
                                });
                                table.reload('LAY-system-apply-orders-table'); //刷新表格
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        });

        form.on('submit(LAY-pla-system-apply-orders-list-filter-form-query)', function (data) {
            table.reload('LAY-system-apply-orders-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: data.field
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>
</body>
</html>
